package com.tadpole.music.holder.question;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tadpole.music.R;
import com.tadpole.music.adapter.base.BaseAdapter;
import com.tadpole.music.bean.question.SpecialPracticeBean;
import com.tadpole.music.holder.base.BaseViewHolder;
import com.tadpole.music.utils.NoDoubleClickListener;

import java.util.List;

/**
 * 专项练习
 * Created By 孙岩
 * on 2020/9/9
 */
public class PracticeViewHolder extends BaseViewHolder {
    private View itemView;
    private List<SpecialPracticeBean.DataBean> list;
    private BaseAdapter.OnChildClickListener onChildClickListener;


    //背景
    private RelativeLayout rlBg;
    //图标
    private ImageView ivIcon;
    //等级
    private TextView tvName;
    //前往练习
    private TextView tvGoPractice;
    private Activity activity;
    public PracticeViewHolder(Activity activity,View itemView, List<SpecialPracticeBean.DataBean> list, BaseAdapter.OnChildClickListener onChildClickListener) {
        super(itemView);
        this.itemView = itemView;
        this.activity = activity;
        this.list = list;
        this.onChildClickListener = onChildClickListener;
    }

    @SuppressLint("UseCompatLoadingForDrawables")
    @Override
    public void init(final int position) {
        tvGoPractice = itemView.findViewById(R.id.tvGoPractice);
        rlBg = itemView.findViewById(R.id.rlBg);
        ivIcon = itemView.findViewById(R.id.ivIcon);
        tvName = itemView.findViewById(R.id.tvName);

        if(position==0){
            rlBg.setBackground(activity.getResources().getDrawable(R.mipmap.practice_bg_one));
            ivIcon.setImageResource(R.mipmap.practice_icon_one);
            tvGoPractice.setTextColor(activity.getResources().getColor(R.color.color_question_one));
        }else if(position==1){
            rlBg.setBackground(activity.getResources().getDrawable(R.mipmap.practice_bg_two));
            ivIcon.setImageResource(R.mipmap.practice_icon_two);
            tvGoPractice.setTextColor(activity.getResources().getColor(R.color.color_question_two));
        }else if(position==2){
            rlBg.setBackground(activity.getResources().getDrawable(R.mipmap.practice_bg_three));
            ivIcon.setImageResource(R.mipmap.practice_icon_three);
            tvGoPractice.setTextColor(activity.getResources().getColor(R.color.color_question_three));
        }else if(position==3){
            rlBg.setBackground(activity.getResources().getDrawable(R.mipmap.practice_bg_four));
            ivIcon.setImageResource(R.mipmap.practice_icon_four);
            tvGoPractice.setTextColor(activity.getResources().getColor(R.color.color_question_four));
        }else if(position==4){
            rlBg.setBackground(activity.getResources().getDrawable(R.mipmap.practice_bg_five));
            ivIcon.setImageResource(R.mipmap.practice_icon_five);
            tvGoPractice.setTextColor(activity.getResources().getColor(R.color.color_question_five));
        }else if(position==5){
            rlBg.setBackground(activity.getResources().getDrawable(R.mipmap.practice_bg_six));
            ivIcon.setImageResource(R.mipmap.practice_icon_six);
            tvGoPractice.setTextColor(activity.getResources().getColor(R.color.color_question_six));
        }

        tvName.setText(list.get(position).getName());

        tvGoPractice.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                onChildClickListener.onChildClick(tvGoPractice,position);
            }
        });
    }
}
